﻿using Microsoft.Practices.Prism.Mvvm;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;

namespace testLibrary2
{
    public class Class1:BindableBase
    {

        public void add ()
            {



            Task.Factory.StartNew(() =>
            {
                while (true)
                {

                    Thread.Sleep(3000); ;
                    ClassCountViewModel vm = new ClassCountViewModel
                    {
                        SecurityID = "111",
                        SecurityName = "111",
                        Time = "111",
                        UpRadio = 0,
                        StockClass = "111",
                        ClassCnt = "111"
                    };
                    Application.Current.Dispatcher.BeginInvoke(new Action(() => {     ///这里要用ui线程 不能用后台线程
                        Classes.Add(vm);                
                    }));

                }
            });
            


            }


        private ObservableCollection<ClassCountViewModel> classes;
        public ObservableCollection<ClassCountViewModel> Classes
        {
            get
            {
                if (classes == null)
                {
                    classes = new ObservableCollection<ClassCountViewModel>();
                }
                return classes;
            }
            set
            {
                SetProperty(ref classes, value, "Classes");
            }
        }

    }
}



public class ClassCountViewModel : BindableBase

{
    public string SecurityID { get; set; }

    public string SecurityName { get; set; }

    public string Time { get; set; }

    public float UpRadio { get; set; }

    public string StockClass { get; set; }

    public string ClassCnt { get; set; }
}